package com.net.xpay.core.validator;

import com.google.common.base.Strings;
import com.net.xpay.common.domain.User;
import com.net.common.exception.BusinessException;
import com.net.common.util.AlipayAccountCheckUtil;
import com.net.common.util.SerializationUtil;
import com.net.xpay.core.constant.PoseidonErrorCode;
import com.net.xpay.core.model.AutoPayReceiptAccountUpdateModel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**自动付用户验证
 * @author 86188
 */
@Component
@Slf4j
public class AutoAccountValidator {
    public void validateUpdateAutoPayAccount(User user, AutoPayReceiptAccountUpdateModel model) {
        log.info("validateUpdateAutoPayAccount model={}| userId ={}", SerializationUtil.obj2String(model), user.getId());
        if (!AlipayAccountCheckUtil.isEffectiveAccount(model.getIdentity())) {
            throw new BusinessException(PoseidonErrorCode.PARAMETER_ILLEGAL, "支付宝账号格式不正确");
        }
        if (Strings.isNullOrEmpty(model.getName())) {
            throw new BusinessException(PoseidonErrorCode.PARAMETER_ILLEGAL, "真实姓名不能为空");
        }
        if (!Strings.isNullOrEmpty(model.getRemark()) && model.getRemark().length() > 50) {
            throw new BusinessException(PoseidonErrorCode.PARAMETER_ILLEGAL, "备注字数不可以超过50字");
        }

    }
}
